﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Extensions;
using DevExpress.Utils;
using DevExpress.XtraEditors;

namespace Tailord
{
    public partial class GomlekSiparisleri : XPopupForm
    {
        private int CustomerId;

        public int OrderId { get; set; }

        public GomlekSiparisleri()
        {
            InitializeComponent();
        }

        public GomlekSiparisleri(int CustomerId):this()
        {
            // TODO: Complete member initialization
            this.CustomerId = CustomerId;
        }

        private void GomlekSiparisleri_Load(object sender, EventArgs e)
        {
            ShowOnlyBar();
            gvSiparisler.Init("GetOrderstoAddRetailOrder", CustomerId);

            gvSiparisler.MakeColumnInvisible("CustomerId");
            gvSiparisler.FormatAsNumber(2, "Indirim", "Fiyat", "NetFiyat");
            gvSiparisler.FormatAsDate("SiparisTarihi", "TeslimTarihi");

            gvSiparisler.BestFitColumns();

            gvSiparisler.RowCellStyle += gvSiparisler_RowCellStyle;
        }

        void gvSiparisler_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e)
        {
            if (e.RowHandle > -1)
            {
                if (e.Column.FieldName == "NetFiyat")
                {
                    e.Appearance.Font = new Font(AppearanceObject.DefaultFont, FontStyle.Bold);
                    e.Appearance.ForeColor = Color.Red;
                }
                else if (e.Column.FieldName == "Indirim" || e.Column.FieldName == "Fiyat" || e.Column.FieldName == "Musteri")
                {
                    e.Appearance.Font = new Font(AppearanceObject.DefaultFont, FontStyle.Bold);
                }

                if (e.RowHandle == gvSiparisler.FocusedRowHandle)
                {
                    e.Appearance.BackColor = Color.Aqua;
                }
            }
        }

        private void bbiEkle_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            SelectedCustomerId = gvSiparisler.GetFocusedRowCellValue("CustomerId").ToIntZero();
            OrderId = gvSiparisler.GetFocusedRowCellValue("FoyNo").ToIntZero();
            if (OrderId<=0)
            {
                XtraMessageBox.Show("Bir gömlek siparişi seçmek zorundasınız!", "Uyarı", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            this.DialogResult = DialogResult.OK;
        }


        public int SelectedCustomerId { get; set; }
    }
}
